# README 


## Overview

The code in this replication package is the same code used for the analysis in Aryal and Zincenko (2024), "Empirical framework for Cournot oligopoly with private information," RAND Journal of Economics, vol. 55, No. 3, pp. 375-402. The data are organized and estimated using MATLAB, and figures and tables are generated using LaTeX. This package can generate most of the figures and tables (including the main results) in the manuscript. The missing figures and tables are generated in either LaTeX or MATLAB. We provide MATLAB codes that generate the necessary data, which can then be exported to create the figures and tables appropriately.  

## Data Availability and Provenance Statements

- [ ] This paper does not involve analysis of external data (i.e., no data are used or the only data are generated by the authors via simulation in their code).



### Statement about Rights

- [X] We certify that the author(s) of the manuscript have legitimate access to and permission to use the data used in this manuscript. 
- [ ] We certify that the author(s) of the manuscript have documented permission to redistribute/publish the data contained within this replication package. Appropriate permissions are documented in the [LICENSE.txt](LICENSE.txt) file.



### Summary of Availability

- [X] All data **are** publicly available.
- [ ] Some data **cannot be made** publicly available.
- [ ] **No data can be made** publicly available.
- [ ] Confidential data used in this paper and not provided as part of the public replication package will be preserved for ___ years after publication, in accordance with journal policies. 

### Details on each Data Source

No source files and "raw" data are made available with the replication package. However, below is a list of the four secondary data sources, along with an example source file used in the programs.


| Data.Name  | Data.Files | Location | Provided |  
| -- | -- | -- | -- | 
| "Crude Oil" | CrudeOil.xls | /data/raw | TRUE | 
| "Import Price" | Price_per_barrel.csv | /data/raw | TRUE | 
| "Deflator" | Deflator.xls | /data/raw | TRUE |  
| "Deflator Oil Drilling"| Deflator_PCU213111213111P.csv| /data/raw | TRUE |

where:

`Crude Oil` is the main dataset, and it is available from the Monthly Energy Review published by the US Energy Information Administration. The Monthly Energy Review is available at [BTS website](https://rb.gy/rygmcz). 


`Import Price` provides oil prices (per barrel) published by the St. Louis Federal Reserve.  


`Deflator` and `Deflator Oil Drilling` give the deflators used in the paper. 




### Software Requirements

- [X] The replication package contains one or more programs to install all dependencies and set up the necessary directory structure.

- MATLAB 
- MIDACO Unlimited Version (see notes below)
  

### Memory, Runtime, Storage Requirements


Data preparation was done in `MATLAB`. The codes should be run on a machine with at least 16 GB of RAM.  


#### Summary

Approximate time needed to reproduce the analyses on a standard (2023) desktop machine:

- [ ] <10 minutes
- [ ] 10-60 minutes
- [ ] 1-2 hours
- [X] 2-8 hours
- [ ] 8-24 hours
- [ ] 1-3 days
- [ ] 3-14 days
- [ ] 14+ days
- [ ] Not feasible to run on a desktop machine, as described below.



### License for Code

The code is licensed under a MIT license. See [LICENSE.txt](LICENSE.txt) for details.


## Instructions to Replicators

There's no need to change the directory for any file. Detailed instructions are in `code/main.m`. The code in that file runs in the following sequence:

### 1. Clean the data
- Run `code/1_analysis/f1_cleaning.m` to create `OilData.mat`.


### 2. Data presentation
- Run `code/1_analysis/f2_data_analysis.m` to create tables and figures used in the data section.


### 3. Estimation Results 
- Run `code/2_estimation/f3_estimating_parameters.m` to estimate the parameters presented in Table 3.
- This code requires MIDACO Unlimited version. See more here: [BTS website](https://www.midaco-solver.com/index.php/about). 
- However, you can replace it with your choice of optimization solver (e.g., fminsearch/fmincon).
- Go to `code/2_estimation/estimate_fun_midaco.m` and use your unlimited key for the code to run. The free version only allows up to 4 variables. Put all relevant MIDACO files into `/2_estimation/f4_estimating_parameters/midaco`
- To use the PPI for oil and gas drilling as deflator, change deflator = 2 in `f3_estimating_parameters.m`


### 4. Confidence Intervals
- Run bootstrap to get the confidence intervals from `code/3_inference/BS_CI.m`
- Run `code/4_counterfactual/after_estimation.m` to get the CI 

### 5. Counterfactual
- Run `code/4_counterfactual/counterfactual.m` to get the counterfactual prices, quantities, and DWL

Note: The codes for the Monte Carlo exercise are not included. The codes provided here are for the estimation exercise only.


---
## List of Table/Figures and associated programs

The provided code reproduces:

| Figure/Table #    | Program                                  |     Note             |    
|-------------------|------------------------------------------|----------------------|
| Figures 1,2, 4    | `code/1_analysis/f2_data_analysis.m`     |                      |
| Figures 5         | code/4_counterfactual/after_estimation.m |                      |
| Tables 1          | `code/1_analysis/f2_data_analysis.m`     |                      |


Note. Figure 3 is omitted because it is based on preliminary k-means estimates, which are subsequently used to construct Groups 1–6.

---
## References

Aryal, Gaurab, and Zincenko, Federico. 2024.  "Empirical framework for Cournot oligopoly with private information." RAND Journal of Economics, volume 55, Issue 3, pp 375-402.




---


